//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.yuan.java.aliyunapi;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;

public class ShowApiLogger {
    private static boolean needEnableLogger = true;

    public ShowApiLogger() {
    }

    public static void setNeedEnableLogger(boolean needEnableLogger) {
        needEnableLogger = needEnableLogger;
    }

    public static void logCommError(Exception e, String url, String appId, Map<String, String> params) {
        if (needEnableLogger) {
            StringBuilder sb = new StringBuilder();
            appendLog(params, sb);
            logCommError(e, url, appId, sb.toString());
        }
    }

    public static void logCommError(Exception e, String urlStr, String appId, String bodyContent) {
        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        df.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        String rspCode = "";
        StringBuilder sb = new StringBuilder();
        sb.append(df.format(new Date()));
        sb.append("_");
        sb.append(appId);
        sb.append("_");
        sb.append(urlStr);
        sb.append("_");
        sb.append(rspCode);
        sb.append("_");
        sb.append(e.getMessage().replaceAll("\r\n", " "));
        sb.append(bodyContent);
        System.err.println(sb.toString());
    }

    private static void appendLog(Map map, StringBuilder sb) {
        boolean first = true;
        Set<Entry<String, String>> set = map.entrySet();

        Entry entry;
        for (Iterator var5 = set.iterator(); var5.hasNext(); sb.append((String) entry.getKey()).append("=").append((String) entry.getValue())) {
            entry = (Entry) var5.next();
            if (!first) {
                sb.append("&");
            } else {
                first = false;
            }
        }

    }
}
